﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Scada.DataApi
{
    /// <summary>
    /// Usage: var c = new Scada.DataApi.Client();
    /// </summary>
    public class Client //: IClient
    {
        private NetDataExchange dataExchange;

        

        private List<Station> stationList;

        private string token;

        public Client()
        {
            this.Connected = false;
        }

        public Client(string username, string password)
        {
            this.Connected = false;
        }

        public bool Connect(string address, int port = 80)
        {
            Task<bool> result = this.ConnectInternal(address, port);
            return result.Wait(5000);
        }

        public Task<bool> ConnectAsync(string address, int port = 80)
        {
            return this.ConnectInternal(address, port);
        }

        private async Task<bool> ConnectInternal(string address, int port)
        {
            this.dataExchange = new NetDataExchange(address, port);
            
            this.Connected = true;
            return true;
        }

        public bool Connected
        {
            get;
            set;
        }

        public Station[] Stations
        {
            get
            {
                return this.stationList.ToArray();
            }

        }

        public void UpdateStationList()
        {
            // TODO:
            this.stationList = this.dataExchange.GetStations();
        }


        public Dictionary<string, string> GetData(string stationId, string deviceId)
        {
            return null;
        }

        
    }
}
